package com.lxh.lxhcrm.model.pojos;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;

/**
 * 报价表
 */
@Entity
public class Offer {
    private int offerId;
    private Integer customerId;
    private Double totalPrice;
    private List<DetailOffer> offerList;  //  报价详情表  一对多


    @ManyToMany
    @JoinTable(name = "offer_list",
            joinColumns = {@JoinColumn(name = "offer_id")},
            inverseJoinColumns = {@JoinColumn(name = "detail_offer_id")}
    )
    public List<DetailOffer> getOfferList() {
        return offerList;
    }

    public void setOfferList(List<DetailOffer> offerList) {
        this.offerList = offerList;
    }

    @Id
    @Column(name = "offer_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getOfferId() {
        return offerId;
    }

    public void setOfferId(int offerId) {
        this.offerId = offerId;
    }

    @Basic
    @Column(name = "customer_id", nullable = true)
    public Integer getCustomerId() {
        return customerId;
    }

    public void setCustomerId(Integer customerId) {
        this.customerId = customerId;
    }

    @Basic
    @Column(name = "total_price", nullable = true, precision = 0)
    public Double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(Double totalPrice) {
        this.totalPrice = totalPrice;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Offer offer = (Offer) o;
        return offerId == offer.offerId &&
                Objects.equals(customerId, offer.customerId) &&
                Objects.equals(totalPrice, offer.totalPrice) &&
                Objects.equals(offerList, offer.offerList);
    }

    @Override
    public int hashCode() {
        return Objects.hash(offerId, customerId, totalPrice, offerList);
    }
}
